require './Modele/Personne'
require "sqlite3"
class Client < Personne
  def initialize(nom,prenom,parking,id=nil)
    super(nom,prenom)
    @parking = parking
    if(id==nil)
      enregistrer_client
      @id = @parking.db.execute("select idclient from CLients where nom = '#{nom}' and prenom ='#{prenom}'")[0][0]
    else
      @id=id
    end
  end
  
  def enregistrer_client
    @parking.db.execute("insert into Clients (nom,prenom,Abonnee,Garanti,nbVenu) 
                                values ('#{@nom}','#{@prenom}','False','False',0)")
  end
  
  def se_garer(vehicule,borne)
    result = borne.delivrer_ticket(vehicule,self)
    if (/[0-9]/.match(result) != nil)
      @parking.db.execute("update Clients set nbVenu=nbVenu+1 where idclient=#{@id}")
    end
    return result
  end
  
  def reprendre_vehicule(ticket,borne)
    borne.reprendre_vehicule(ticket) 
  end
 
end